using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Husb.Util;
using Husb.Util.Enum;
using CentralOffice.Task.Data;
using CentralOffice.Task.DataAccess;
using CentralOffice.Task.BusinessActions;

using TaskTable = CentralOffice.Task.Data.TaskDataSet.TasksDataTable;
using TaskRow = CentralOffice.Task.Data.TaskDataSet.TasksRow;

namespace CentralOffice.WebClient.Files
{
    public partial class FilesForTask : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                SiteUtil.PopulateListBox(ddlPriority, SiteConstants.TaskPriority, true);
                ddlPriority.SelectedIndex = 0;

                SiteUtil.PopulateListBox(ddlStatus, SiteConstants.TaskStatus, true);
            }
        }

        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gv.PageIndex = 0;

            TaskRow task = (new TaskDataSet()).Tasks.NewTasksRow();

            task.Name = txtName.Text;
            if (ddlCategory.SelectIndex > 0 && ddlCategory.SelectId != null)
            {
                task.CategoryId = ddlCategory.SelectId.Value;
            }

            if (ddlPriority.SelectedIndex > 0)
            {
                task.Significant = ddlPriority.SelectedItem.Text;
            }
            if (ddlStatus.SelectedIndex > 0)
            {
                task.Status = ddlStatus.SelectedItem.Text;
            }
            task.Sponsor = txtSponsor.Text;
            task.Accepter = txtAccepter.Text;

            if (txtIntendingDate.Text.Length > 0)
            {
                task.IntendingDate = DateTime.Parse(txtIntendingDate.Text);
            }
            if (txtApprovedDate.Text.Length > 0)
            {
                task.ApprovedDate = DateTime.Parse(txtApprovedDate.Text);
            }
            

            odsTask.SelectParameters.Clear();
            odsTask.SelectParameters.Add("whereClause", task.FilterExpression);
        }

        protected void gv_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = gv.SelectedRow;

            //object role = row.DataItem;

            //PopulateCategoryTree(row.Cells[1].Text);

            //Message.Text = "You selected " + row.Cells[2].Text + ".";
            gvFile.DataSource = File.BusinessActions.Files.GetByTaskId((Guid)gv.DataKeys[row.RowIndex].Value);
            gvFile.DataBind();

            upFiles.Update();
        }
    }
}
